package io.renren.modules.echarts.service.Impl;

import io.renren.modules.echarts.dao.StudentAttendenceECharts;
import io.renren.modules.echarts.entity.TeacherEvaltionPieEntity;
import io.renren.modules.echarts.service.StudentAttendenceEChartsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class StudentAttendenceEChartsServiceImpl implements StudentAttendenceEChartsService {
    @Autowired
    TeacherPortraitServiceImpl teacherPortraitService;
    @Autowired
    StudentAttendenceECharts studentAttendanceEcharts;
    public Map studentAttendanceRate(Map<String, Object> params) {
        String valid=teacherPortraitService.ValidDatesConverter(params);
        //加入肯德基豪华套餐
        params.put("ValidDates",valid);
        List<TeacherEvaltionPieEntity> list=  studentAttendanceEcharts.studentAttendanceRate(params);
        List<String> legend=new ArrayList<>();
        List<TeacherEvaltionPieEntity> series=new ArrayList<>();
        for(TeacherEvaltionPieEntity t:list)
        {
            if(t.getName().equals("出勤"))
            {
                series.add(t);
                legend.add(t.getName());
            }
        }
        for(TeacherEvaltionPieEntity t:list)
        {
            if(t.getName()!=null&&!t.getName().equals("出勤"))
            {
                series.add(t);
                legend.add(t.getName());
            }
        }
        Map map=new HashMap();
        map.put("legend",legend);
        map.put("series",series);
        return map;
    }
    public Map<String, List> studentAttendanceRateTimeLine(Map<String, Object> params) {
        String valid=teacherPortraitService.ValidDatesConverter(params);
        //加入肯德基豪华套餐
        params.put("ValidDates",valid);
        List<TeacherEvaltionPieEntity> classDiaryList=studentAttendanceEcharts.studentAttendanceRateTimeLine(params);
        List<String> xData=new ArrayList<>();
        List<TeacherEvaltionPieEntity> series=new ArrayList<>();
        for(TeacherEvaltionPieEntity t:classDiaryList)
        {
            if(t.getName()!=null)
            {
                series.add(t);
                xData.add(t.getName());
            }
        }
        Map map=new HashMap();
        map.put("xData",xData);
        map.put("seriesData",series);
        return map;
    }
}
